package com.qk.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.qk.common.PageResult;
import com.qk.dto.Coursedto;
import com.qk.entity.Course;
import com.qk.mapper.CourseMapper;
import com.qk.service.CourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class CourseServiceimpl implements CourseService {
    @Autowired
    private CourseMapper courseMapper;

    @Override
    public PageResult<Course> list(Coursedto coursedto) {
        PageHelper.startPage(coursedto.getPage(),coursedto.getPageSize());
        List<Course> courselist=courseMapper.listAll(coursedto);
        Page<Course> page =(Page<Course>) courselist;
        return new PageResult<>(page.getTotal(),page.getResult());
    }

    @Override
    public void delete(Integer id) {
        courseMapper.delete(id);
    }

    @Override
    public void insert(Course course) {
        course.setCreateTime(LocalDateTime.now());
        course.setUpdateTime(LocalDateTime.now());
        courseMapper.insert(course);

    }

    @Override
    public Course getById(Integer id) {
        Course course = courseMapper.getById(id);
        return course;
    }

    @Override
    public void update(Course course) {
        course.setUpdateTime(LocalDateTime.now());
        courseMapper.update(course);
    }

    @Override
    public List<Course> listAll() {
        List<Course> courseList = courseMapper.listAllcourse();
        return courseList;
    }

    @Override
    public List<Course> listBySubject(Integer subject) {
        List<Course> courseList = courseMapper.listBySubject(subject);
        return courseList;
    }
}
